package cn.pn.project.client.base;

import cn.pn.project.client.base.fallback.AddressFeignFallBack;
import cn.pn.project.module.base.AddressModule;
import cn.pn.project.pojo.base.Address;
import cn.pn.project.vo.base.AddressVo;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.sql.SQLException;
import java.util.List;

@FeignClient(name="pn-base-provider",fallback = AddressFeignFallBack.class)
@RequestMapping("/address")
public interface AddressFeign {
    /**
     * 添加地址方法
     * @param address 所需参数   除去addressId剩下的都要
     * @return
     * @throws RuntimeException
     */
    @PostMapping ("/add")
    boolean addAddress(@RequestBody Address address) throws RuntimeException;

    /**
     * 修改地址
     * @param address 一个完整的对象，某些属性没有改变时这个属性里必须存在原来的值
     * @return
     * @throws RuntimeException
     */
    @PostMapping("/change")
    boolean changeAddress(@RequestBody Address address) throws RuntimeException ;

    /**
     * 删除地址
     * @param address  地址id 用户id 必须保证要存在这两个数据
     * @return
     * @throws RuntimeException
     */
    @PostMapping("/remove")
    boolean removeAddress(@RequestBody Address address) throws RuntimeException ;

    /**
     * 查询
     * @param address userId 必须存在  isDefaultAddress  必须存在
     * @return
     * @throws RuntimeException
     */
    @PostMapping("/select")
    List<AddressModule> findAddressByUserId(@RequestBody Address address) throws RuntimeException ;

    /**
     * 新旧默认地址更替 在订单生成时
     * @param addressVo oid 原来的默认地址id   new 本次订单选择的id
     * @throws RuntimeException
     * @throws SQLException
     */
    @PostMapping("/defaultAddressReplace")
    void defaultAddressReplace(@RequestBody AddressVo addressVo) throws RuntimeException, SQLException;
}
